<template>
  <div class="content">
    <el-form
      :inline="true"
      :model="formInline"
      class="demo-form-inline"
    >
      <el-form-item label="订单时间">
        <BiDatePicker
          v-model="formInline.order_time"
          clearable
          size="small"
          type="daterange"
          format="yyyy-MM-dd"
          style="width:280px;"
          value-format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          :loading="loading"
          type="primary"
          style="margin-left:10px;"
          @click="startSearch"
        >查询</el-button>
      </el-form-item>
    </el-form>
    <div class="table-table">
      <BiTable
        :loading="loading"
        :data="tableData"
        size="medium"
        :column="tableColums"
        fixed="sticky"
        fixed-offset="50"
        pagination
        layout="total, prev, pager, next"
        :auto-scroll="false"
        :total="page_info.total"
        :page.sync="page_info.page"
        :limit.sync="page_info.page_size"
        @pagination="handlePageChange"
      >
      </BiTable>
    </div>
  </div>
</template>

<script>
import { vipRecord } from '@/api/userPage'
import { formatNumber } from '@/utils/index'
export default {
  props: ['rowInfo'],
  data() {
    return {
      formInline: {
        order_time: [],
        order_time_start: '',
        order_time_end: '',
        member_id: ''
      },
      loading: false,
      tableData: [],
      tableColums: [
        {
          label: '订单编号',
          prop: 'order_no',
          width: 320
        },
        {
          label: '会员类型',
          prop: 'product_name',
          width: 200
        },
        {
          label: '订单时间',
          prop: 'order_time',
          width: 160
        },
        {
          label: '订单金额',
          prop: 'amount',
          render: (h, { row }) => {
            return <span>{formatNumber(row.amount)} </span>
          }
        },
        {
          label: '会员起始时间',
          prop: 'vip_start_time',
          width: 160
        },
        {
          label: '会员终止时间',
          prop: 'vip_end_time',
          width: 160
        },
        {
          label: '订单会员状态',
          prop: 'vip_status',
          width: 130,
          renderHeader: (h, { row }) => {
            return (
              <div>
                订单会员状态
                <el-tooltip class='item' effect='dark' placement='top'>
                  <div slot='content'>
                    <p>已失效：订单如发生退款会失效</p>
                    <p>生效中：未发生退款订单</p>
                  </div>
                  <i class='el-icon-question' style='margin-left:5px;'></i>
                </el-tooltip>
              </div>
            )
          },
          render: (h, { row }) => {
            if (row.vip_status == 1) {
              return <span>生效中 </span>
            } else if (row.vip_status == 2) {
              return <span>已失效 </span>
            }
            return <span></span>
          }
        }
      ],
      page_info: {
        page: 1,
        page_size: 20,
        total: 0
      }
    }
  },
  mounted() {
    this.clickSearch('type')
  },
  methods: {
    handlePageChange(page) {
      this.page_info.page = page.page
      this.clickSearch()
    },
    startSearch() {
      this.page_info.page = 1
      this.clickSearch()
    },
    clickSearch(type) {
      const data = {
        order_time_start: (this.formInline.order_time && this.formInline.order_time[0]) || '',
        order_time_end: (this.formInline.order_time && this.formInline?.order_time[1]) || '',
        member_id: this.rowInfo.member_id
      }
      this.loading = true
      vipRecord({ ...data, ...this.page_info }).then((res) => {
        if (res.status_code === 1) {
          this.page_info = res.data.page_info
          this.tableData = res.data.data
          !type ? this.$message.success(res.msg) : ''
        }
        this.loading = false
      })
    }
  }
}
</script>

<style lang="scss" scoped>
</style>